package gqz.mvvm.view;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import java.util.Timer;
import java.util.TimerTask;

import gqz.mvvm.R;
import gqz.mvvm.view.custom.HeartLayout;

/**
 * Created by Administrator on 2017/12/9.
 */

public class HeartActivity extends BaseActivity implements View.OnClickListener {

    String TAG = "HeartActivity--";

    HeartLayout rootl;
    ImageView btn_addHeart;

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            rootl.addHeart(btn_addHeart.getX(), btn_addHeart.getY());
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_heart);
        rootl = (HeartLayout) findViewById(R.id.heart_root);
        btn_addHeart = (ImageView) findViewById(R.id.heart_btn_addHeart);
        btn_addHeart.setOnClickListener(this);

        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(0);
            }
        }, 0, 200);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.heart_btn_addHeart:
                rootl.addHeart(v.getX(), v.getY());
                break;
        }
    }

}
